
package GUI;

import CLIENT.Client;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

/**
 * This Class Is The Frame Of a Private Chat
* @author Avi Cohen
 */

public class PrivateChatFrame extends JFrame implements WindowListener,ActionListener
{
    PrivateChatPanel _PrivateChatP;
     Image _wall;
     Image _image3DP;
     JMenuBar _menu;
    JMenuItem _exit;
    JMenu _changeTheme;
    JMenuItem _histoy;
    JMenuItem _invite;
    JMenuItem _attach;
    JMenuItem _music;
    JMenuItem _Theme1;
    JMenuItem _Theme2;
    JMenuItem _Theme3;
    JMenuItem _Theme4;
    String _chatwith;
    Client _client;


/**
  * Constroctor for The PrivateChatFrame
 * @param privateChatWith - The Name of the person the private chat is with
 * @param outpurStream - the outpurstream to connect to the second person
 * @param client -
 */
    public PrivateChatFrame(String privateChatWith, ObjectOutputStream outputStream, Client client)
    {
        this.setTitle("Private Chat With "+privateChatWith);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setResizable(false);//the window size cannot be changed
         //setting the Layout Manager
            BorderLayout layout=new BorderLayout();
            this.getContentPane().setLayout(layout);
            _client = client;
             _chatwith = privateChatWith;
        // Read Image
            _image3DP=Toolkit.getDefaultToolkit().getImage("Pics/3D Postman No BG.gif");

        //create the menu bar
            _menu=new JMenuBar();
            _menu.setBorderPainted(true);
            //create the JMenus
                JMenu _file=new JMenu("File");
                _menu.add(_file);
                //createMenu Items
                    //file menu
                        _exit=new JMenuItem("Exit");
                        _exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,InputEvent.ALT_DOWN_MASK ));//set shortcut
                        _exit.addActionListener(this);
                        _file.add(_exit);//add "exit" to "file"

                this.getContentPane().add(_menu,BorderLayout.PAGE_START);

        //create a new private chat panel
        _PrivateChatP = new PrivateChatPanel(_client, outputStream, _chatwith);
        _PrivateChatP.setToolTipText(this.getTitle());
        this.getContentPane().add(_PrivateChatP);

        this.setIconImage(_image3DP);//add the picture as an Frame icon
        this.setSize(820, 630);
        this.addWindowListener(this);

    }

    /**
     * This Function Handle Menu Buttons Events
     * @param e - the event that accured
     */
    public void actionPerformed(ActionEvent e)
    {
        //******Menu button events***********//
            if(e.getSource()==_exit)//if the exit menu button pressed
            {
                this.setVisible(false);
            }
             if(e.getSource()==_Theme1)//if the Theme 1 menu button pressed (Green theme)
            {
                _PrivateChatP.ChangeTheme(new Color(60,179,113),new Color(152, 251, 152));
            }
            if(e.getSource()==_Theme2)//if the Theme 2 menu button pressed (blue theme)
            {
                _PrivateChatP.ChangeTheme(Color.blue, Color.cyan);
            }
            if(e.getSource()==_Theme3)//if the Theme 3 menu button pressed (red theme)
            {
                _PrivateChatP.ChangeTheme(Color.RED, Color.pink);
            }
            if(e.getSource()==_Theme4)//if the Theme 4 menu button pressed (office theme)
            {
                _PrivateChatP.ChangeTheme(Color.DARK_GRAY, Color.LIGHT_GRAY);
            }


        
    }
    /**
     *
     * @return Who The Chat is with
     */
    public String GetChatWith()
    {
        return _chatwith;
    }
    /**
     *
     * @return - The Panel that associated to this Frame
     */
    public PrivateChatPanel GetPrivateChatP()
    {
        return _PrivateChatP;
    }

    public void windowOpened(WindowEvent e) {}
    public void windowClosing(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e){}
    public void windowActivated(WindowEvent e){}
    public void windowDeactivated(WindowEvent e){}


}
